<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui"                
                xmlns:bi="http://java.sun.com/jsf/composite/bill"
                xmlns:pa="http://java.sun.com/jsf/composite/paymentMethod">

    <ui:define name="content">
        <h:form  >
            <h:panelGroup >
                <p:panel rendered="#{!agentPaymentRecieveBillController.printPreview}" >
                    <f:facet name="header" >
                        <h:panelGrid columns="15"  >
                            <h:outputLabel value="Agent Payment Bills" />
                            <h:outputLabel value="&nbsp;&nbsp;&nbsp;&nbsp;" style="min-width: 50px;" />
                            <p:selectOneMenu   id="cmbPs" value="#{agentPaymentRecieveBillController.current.paymentMethod}">                                                                     
                                <f:selectItems value="#{enumController.paymentMethodsWithoutCredit}"/>
                                <p:ajax process="cmbPs" update="creditCard cheque slip" event="change" />
                            </p:selectOneMenu>
                            
                            <p:inputText value="#{agentPaymentRecieveBillController.comment}" id="comment"/>
                            <p:watermark value="Comment" for="comment"/>

                            <h:panelGroup id="creditCard" style="display: #{agentPaymentRecieveBillController.current.paymentMethod ne 'Card' ? 'none' : 'block'} ; ">
                                <pa:creditCard paymentMethodData="#{agentPaymentRecieveBillController.paymentMethodData}"/>
                            </h:panelGroup>

                            <h:panelGroup id="cheque" style="display: #{agentPaymentRecieveBillController.current.paymentMethod ne 'Cheque' ? 'none' : 'block'} ; " >
                                <pa:cheque paymentMethodData="#{agentPaymentRecieveBillController.paymentMethodData}"/>
                            </h:panelGroup>

                            <h:panelGroup id="slip" style="display: #{agentPaymentRecieveBillController.current.paymentMethod ne 'Slip' ? 'none' : 'block'} ;">
                                <pa:slip paymentMethodData="#{agentPaymentRecieveBillController.paymentMethodData}"/>
                            </h:panelGroup>

                            <p:commandButton id="btnSettle" value="Settle" action="#{agentPaymentRecieveBillController.channellAgencyPaymentRecieveSettleBill}" ajax="false"  style="width: 150px; padding: 1px;border: 1px solid ; margin: auto;" onclick="onSubmitButton();">
                            </p:commandButton> 
                            <p:defaultCommand target="btnSettle"/>

                            <p:commandButton value="New Bill" ajax="false" action="#{agentPaymentRecieveBillController.prepareNewBill()}"  onclick="onSubmitButton();">
                            </p:commandButton>
                        </h:panelGrid>
                    </f:facet>

                    <p:panelGrid columns="2" style="min-width: 100%;">
                        <p:outputLabel value="Agency" />
                        <p:autoComplete id="creditCom" forceSelection="true" value="#{agentPaymentRecieveBillController.current.fromInstitution}"  completeMethod="#{agencyController.completeAgency}" var="ix" itemLabel="#{ix.name}" itemValue="#{ix}" size="30"  style="width: 400px;">
                            <f:ajax  event="itemSelect" execute="creditCom"  />
                            <p:column>#{ix.institutionCode}</p:column>
                            <p:column>#{ix.name}</p:column>
                        </p:autoComplete>
                        <p:outputLabel value="Payment" />
                        <p:inputText autocomplete="off" value="#{agentPaymentRecieveBillController.current.netTotal}"/>                               
                        <p:outputLabel value="Description"/>
                        <p:inputTextarea value="#{agentPaymentRecieveBillController.current.comments}"/>                                                         
                    </p:panelGrid>
                </p:panel>
            </h:panelGroup>


            <h:panelGroup rendered="#{agentPaymentRecieveBillController.printPreview}" >     
                <p:commandButton value="New Bill" ajax="false" action="#{agentPaymentRecieveBillController.prepareNewBill()}"  onclick="onSubmitButton();">
                </p:commandButton>
                <bi:agent billController="#{agentPaymentRecieveBillController}"  bill="#{agentPaymentRecieveBillController.current}" dup="false"/>     
            </h:panelGroup>        

        </h:form>
    </ui:define>

</ui:composition>
